﻿using System;
using UnityEngine;

// Token: 0x020000A6 RID: 166
public class RigidBrake : MonoBehaviour
{
	// Token: 0x06000531 RID: 1329 RVA: 0x0001E98C File Offset: 0x0001CB8C
	private void Start()
	{
		this.rig = base.GetComponent<Rigidbody>();
		this.normalDrag = this.rig.drag;
		this.normalAngularDrag = this.rig.angularDrag;
	}

	// Token: 0x06000532 RID: 1330 RVA: 0x0001E9BC File Offset: 0x0001CBBC
	private void Update()
	{
		if (this.hitted && this.timer < this.lockTime)
		{
			this.timer += Time.deltaTime;
		}
		if (this.stayBrake)
		{
			if (this.hitNow)
			{
				this.hitNow = false;
			}
			else
			{
				this.rig.drag = this.normalDrag;
				this.rig.angularDrag = this.normalAngularDrag;
			}
		}
	}

	// Token: 0x06000533 RID: 1331 RVA: 0x0001EA3C File Offset: 0x0001CC3C
	private void OnCollisionEnter(Collision col)
	{
		this.rig.velocity = this.rig.velocity * this.brake;
		this.rig.drag = this.hitDrag;
		this.rig.angularDrag = this.hitAngularDrag;
		this.hitted = true;
		this.hitNow = true;
	}

	// Token: 0x06000534 RID: 1332 RVA: 0x0001EA9C File Offset: 0x0001CC9C
	private void OnCollisionStay(Collision col)
	{
		this.hitNow = true;
		if (this.stayBrake)
		{
			this.rig.velocity = this.rig.velocity * this.brake;
			this.rig.drag = this.hitDrag;
			this.rig.angularDrag = this.hitAngularDrag;
		}
		if (this.timer >= this.lockTime)
		{
			this.rig.isKinematic = true;
			base.transform.SetParent(col.collider.transform);
			Collider[] componentsInChildren = base.GetComponentsInChildren<Collider>();
			foreach (Collider collider in componentsInChildren)
			{
				collider.enabled = false;
			}
		}
	}

	// Token: 0x04000428 RID: 1064
	private Rigidbody rig;

	// Token: 0x04000429 RID: 1065
	public float brake = 0.1f;

	// Token: 0x0400042A RID: 1066
	public bool stayBrake;

	// Token: 0x0400042B RID: 1067
	public float lockTime = 1f;

	// Token: 0x0400042C RID: 1068
	public float hitDrag = 10f;

	// Token: 0x0400042D RID: 1069
	public float hitAngularDrag = 10f;

	// Token: 0x0400042E RID: 1070
	private float timer;

	// Token: 0x0400042F RID: 1071
	private bool hitted;

	// Token: 0x04000430 RID: 1072
	private float normalDrag;

	// Token: 0x04000431 RID: 1073
	private float normalAngularDrag;

	// Token: 0x04000432 RID: 1074
	private bool hitNow;
}
